package com.example.demo.model;

import com.example.demo.enums.ResultCode;
import lombok.Data;

@Data
public class Result<T> {
    // SUCCESS, FAIL, NO_LOGIN
    private ResultCode code;
    private String errMsg;
    // 需要返回的数据
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result<T> fail(String errMsg, T data){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> noLogin(){
        Result<T> result = new Result<>();
        result.setCode(ResultCode.NO_LOGIN);
        result.setErrMsg("用户未登录");
        return result;
    }
}
